<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>大事件-后台登录页</title>
  <link rel="stylesheet" type="text/css" href="css/reset.css" />
  <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <!-- 引入bootstrap的css文件 -->
  <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css" />
  <!-- 引入jq文件 -->
  <script src="./libs/jquery-1.12.4.min.js"></script>
  <!-- 引入bootstrap的js文件 -->
  <script src="./libs/bootstrap/js/bootstrap.min.js"></script>
  <script src="./libs/https.js"></script>

</head>

<body>
    <!-- 准备模态框的静态结构代码 -->
    <div class="modal fade" tabindex="-1" role="dialog" id="myModal">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">温馨提示</h4>
          </div>
          <div class="modal-body">
            <p>One fine body&hellip;</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
          </div>
        </div>
        <!-- /.modal-content -->
      </div>
      <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->

  <div class="main_wrap">
    <div class="header">
      <a href="#" class="logo"><img src="images/logo.png" alt="" /></a>
      <div class="copyright">
        CopyRight © 2019 深圳百秀信息技术股份有限公司<br />All Rights Reserved
      </div>
    </div>

    <div class="login_form_con">
      <div class="login_title"></div>
      <form class="login_form">
        <i class="iconfont icon-user"></i>
        <i class="iconfont icon-key"></i>
        <input type="text" class="input_txt" placeholder="邮箱/手机号" />
        <input type="password" class="input_pass" placeholder="密码" />
        <input type="submit" class="input_sub" value="登 录" />
      </form>
    </div>
  </div>

</body>

</html>
<script>
  $(function () {
    //1. 给登录按钮设置点击事件
    $('.input_sub').on('click',function(e){
      e.preventDefault()
      // 2. 获得用户信息
      let username = $('.input_txt').val().trim();
      let password = $('.input_pass').val().trim();
      // 3. 非空判断
      if (username == '' || password == '') {
        // alert('小哥哥小姐姐,不能留空哦!')
        // 调用框架的模态框显示
        $('.modal-body p').text('小哥哥小姐姐,不能留空空哦!阿巴阿巴...')
        $('#myModal').modal()
        return
      } else {
        // 4. 发起ajax请求,验证用户信息 
        $.ajax({
          type: 'post',
          // url: 'http://localhost:8080/api/v1/admin/user/login',
          url: BigNew.user_login,
          data: {
            username:username,
            password:password
          },
          success: function(backData) {
            // console.log(backData);
            // alert(backData.msg)
             // 注意: 模态框不会卡住程序的运行
          $('.modal-body p').text(backData.msg)
          $('#myModal').modal()

          // 监听模态框隐藏之后,再执行某些操作
          $('#myModal').on('hidden.bs.modal', function (e) {
            
            // 5. 判断是否成功
            if (backData.code == 200) {
              // 6. 将后台返回的token保存到本地缓存中

              // eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiYWRtaW4iLCJleHAiOjIyNDM2NjAwNDUsImlhdCI6MTYzODg2MDA0NX0.O0Cr8NJljNgc4YrlJU0lAvoq9lUnp3uCWZL3R8C5N5L4kIIPNuxpg9lrVtDcKlRI-P3PB6JuEN09Rr4aZTDqsYekhNXCD3ZL4v3wb8ozcGKNY_2QEcDtNupuU4y0su0eLpCU0yqC5rVzPbB8Ps1RRrKOdnaBGTmP-mF-dzEL7xg
              localStorage.setItem('token78', backData.token);
              window.location = './index.html'
              
            } else {
              $('.input_txt').val('');
              $('.input_pass').val('');
            }
            })
          },
        })
      }
    })
  })
</script>